(CM-936) Content design error message tweaks#678
Draft
pezholio wants to merge 9 commits into
Draft
Conversation
This allows us to recursively go through each schema’s subschema and recursively fetch any fields contained within the subschema. I’ve also added an `all_nested_fields` method to the `Field` class to fetch any nested fields inside each field. This will allow us to be able to fetch fields from the validation context to make translation easier.
This accepts an `error_type` argument, and builds up the I18n path to fetch a translated error message, falling back to the default error message for a particular error type. It also accepts additional arguments, which can be used in interpolation.
This updates the validator to fetch a field object based on an ID, and fetch the error message from the field, meaning we have to do less jiggery pokery with the translations from within the validator, and make the lookups more specific.
Most of the suggested error message copy comes in the format: ``` Enter a/an $attribute ``` To save having to add translations for every field in this vein, we update the `error_message` translation to send the attribute prefixed with an indefinite article (a/an) using the existing `add_indefinite_article` helper method. We also `downcase` the atrribute name to avoid the issue of having capital letters in the middle of sentences.
Not all translations will use the default quite so easily, so let’s add these ones manually
4160a51 to
b617f2d
Compare
This ensures that when a title is missing, the correct translation is used for the title field, rather than `Enter a title` and `Title must include as least one letter or number` I’ve also had to set the error message `format` to just return the `message`, rather than prefixing with the attribute, otherwise we would see `Title contact name must include at least one letter or number`
b617f2d to
8a43861
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This addresses most of the error message suggestions made in the content design review. As most of the errors on required fields are in the format
Enter a $thing, I've made some tweaks to make translation lookups more predictable, as well as adding the ability to add the correct indefinite article (a/an) to the field name.I haven't had chance to check if this addresses all of the suggestions in the document, and may not have chance as today's my last day, so gonna leave this in draft for now.